rm update
[EroBeats.git] / Djinn and Tonic - Erobeats / ModeSelect.cpp
blobc9d6a0607b47475d16b646950564a35ffae736e6
1 #include "ModeSelect.h"
3 #include "RescourceKeys.h"
4 #include "ScreenNames.h"
6 ModeSelect::ModeSelect(int* scrs, FileIO* fileIO, ResourceMaster* resourcePointer)
8 hoverArcade = false;
9 hoverLife = false;
10 hoverStart = false;
12 hoverAddress = false;
13 hoverAddressOld = false;
15 rsc = resourcePointer;
16 fio = fileIO;
18 renderer = rsc->rendPtr;
19 screen = scrs;
21 outlineAnimation = new Animation(rsc->gameAnimations.at(WhiteBlueBG));
22 animations[0] = new Animation(fio->loadSpecificZip("1_0.zip"));
23 animations[1] = new Animation(fio->loadSpecificZip("1_1.zip"));
24 font = new Fonts(0, rsc);
26 std::string hs = std::to_string(fio->loadScoreData(1, *screen % 50));
27 if (hs == "0") {
28 highscore = "Highscore: ----";
30 else {
31 highscore = "Highscore: " + hs;
34 std::string hl = std::to_string(fio->loadScoreData(2, *screen % 50));
35 if (hl == "0") {
36 highlife = "Highlife: ----";
38 else {
39 highlife = "Highlife: " + hl;
42 createFonts();
43 gameLoop();
47 ModeSelect::~ModeSelect()
51 int ModeSelect::getGameMode() {
52 return gameMode;
56 void ModeSelect::createFonts() {
57 int textSizeX = font->prcnt(0.20, 'x');
58 int textSizeY = font->prcnt(0.15, 'y');
59 int textAlignX = font->prcnt(0.10, 'x');
60 int offsetAlignX = font->prcnt(0.17, 'x');
61 int centerAlignX = font->prcnt(0.45, 'x');
63 if (gameMode == 0) {
64 font->loadFont(SDL_Color{ 100,100,100,00 }, rsc->gameText.at(GoalText), 2);
66 else if (gameMode == 1) {
67 font->loadFont(SDL_Color{ 100,100,100,00 }, rsc->gameText.at(ArcadeText), 2);
69 else if (gameMode == 2) {
70 font->loadFont(SDL_Color{ 100,100,100,00 }, rsc->gameText.at(LifeText), 2);
73 textGoal = font->getTexture();
74 rectGoal = { textAlignX, font->prcnt(0.03, 'y'), textSizeX , textSizeY };
77 if (gameMode == 0) {
78 font->loadFont(SDL_Color{ 100,100,100,00 }, rsc->gameText.at(SubGoalText), 2);
79 rectSubGoal = { offsetAlignX , font->prcnt(0.14, 'y'), textSizeX , textSizeY };
81 else if (gameMode == 1) {
82 font->loadFont(SDL_Color{ 100,100,100,00 }, rsc->gameText.at(ArcadeGoalText), 2);
83 rectSubGoal = { offsetAlignX, font->prcnt(0.14, 'y'), textSizeX * 4 , textSizeY };
85 else if (gameMode == 2) {
86 font->loadFont(SDL_Color{ 100,100,100,00 }, rsc->gameText.at(LifeGoalText), 2);
87 rectSubGoal = { offsetAlignX, font->prcnt(0.14, 'y'), textSizeX * 3 , textSizeY };
89 textSubGoal = font->getTexture();
91 font->loadFont(SDL_Color{ 255,255,255,00 }, rsc->gameText.at(ArcadeText), 2);
92 textArcade = font->getTexture();
93 rectArcade = { textAlignX, font->prcnt(0.27, 'y'), textSizeX , textSizeY };
95 font->loadFont(SDL_Color{ 100,100,100,00 }, highscore, 2);
96 textHighScore = font->getTexture();
97 rectHighScore = { offsetAlignX, font->prcnt(0.37, 'y'), textSizeX , textSizeY };
99 font->loadFont(SDL_Color{ 255,255,255,00 }, rsc->gameText.at(LifeText), 2);
100 textLife = font->getTexture();
101 rectLife = { textAlignX, font->prcnt(0.50, 'y'), textSizeX , textSizeY };
103 font->loadFont(SDL_Color{ 100,100,100,00 }, highlife, 2);
104 textHighLife = font->getTexture();
105 rectHighLife = { offsetAlignX, font->prcnt(0.60, 'y'), textSizeX , textSizeY };
107 if (gameMode == 0) {
108 font->loadFont(SDL_Color{ 100,100,100,00 }, rsc->gameText.at(StartText), 2);
110 else {
111 font->loadFont(SDL_Color{ 255,255,255,00 }, rsc->gameText.at(StartText), 2);
113 textStart = font->getTexture();
114 rectStart = { centerAlignX, font->prcnt(0.78, 'y'), font->prcnt(0.266, 'x'), font->prcnt(0.20, 'y') };
118 void ModeSelect::destroyFonts() {
119 SDL_DestroyTexture(textArcade);
121 SDL_DestroyTexture(textHighScore);
123 SDL_DestroyTexture(textLife);
125 SDL_DestroyTexture(textHighLife);
127 SDL_DestroyTexture(textGoal);
129 SDL_DestroyTexture(textSubGoal);
131 SDL_DestroyTexture(textStart);
135 void ModeSelect::update() {
136 hoverArcade = false;
137 hoverLife = false;
138 hoverStart = false;
140 if (modeSelected && x > rectStart.x && x < rectStart.x + rectStart.w && y > rectStart.y && y < rectStart.y + rectStart.h) {
141 hoverStart = true;
143 else if (x > rectLife.x && x < rectLife.x + rectLife.w && y > rectLife.y && y < rectLife.y + rectLife.h) {
144 hoverLife = true;
146 else if (x > rectArcade.x && x < rectArcade.x + rectArcade.w && y > rectArcade.y && y < rectArcade.y + rectArcade.h) {
147 hoverArcade = true;
150 if (mouseClicked && hoverStart && modeSelected) {
151 running = false;
153 else if (mouseClicked && hoverArcade) {
154 modeSelected = true;
155 gameMode = 1;
156 destroyFonts();
157 createFonts();
159 else if (mouseClicked && hoverLife) {
160 modeSelected = true;
161 gameMode = 2;
162 destroyFonts();
163 createFonts();
166 if (mouseClickedR) {
167 running = false;
168 *screen = LevelSelectScreen;
171 void ModeSelect::play() {
172 if (hoverStart) {
173 hoverAddress = &hoverStart;
175 if (hoverLife) {
176 hoverAddress = &hoverLife;
178 if (hoverArcade) {
179 hoverAddress = &hoverArcade;
181 if (mouseClicked && (hoverStart || hoverArcade || hoverLife) && !playedOnceL) {
182 rsc->sptr->playSFX(0);
183 playedOnceL = true;
185 else if (mouseClicked && playedOnceL) {
186 playedOnceL = true;
188 else{
189 playedOnceL = false;
191 if (!playedOnce && (hoverStart|| hoverArcade || hoverLife) || hoverAddress != hoverAddressOld) {
192 rsc->sptr->playSFX(1);
193 playedOnce = true;
195 else if (playedOnce && (hoverStart || hoverArcade || hoverLife)) {
196 playedOnce = true;
198 else {
199 playedOnce = false;
201 hoverAddressOld = hoverAddress;
203 void ModeSelect::render() {
204 SDL_RenderClear(renderer);
206 SDL_RenderCopy(renderer, rsc->gameGraphics.at(LangBGFake), NULL, NULL);
208 if (hoverStart) {
209 SDL_RenderCopy(renderer, outlineAnimation->itterateAnimation(30), NULL, &rectStart);
211 else if (hoverLife) {
212 SDL_RenderCopy(renderer, outlineAnimation->itterateAnimation(30), NULL, &rectLife);
214 else if (hoverArcade) {
215 SDL_RenderCopy(renderer, outlineAnimation->itterateAnimation(30), NULL, &rectArcade);
218 SDL_RenderCopy(renderer, textArcade, NULL, &rectArcade);
219 SDL_RenderCopy(renderer, textHighScore, NULL, &rectHighScore);
220 SDL_RenderCopy(renderer, textLife, NULL, &rectLife);
221 SDL_RenderCopy(renderer, textHighLife, NULL, &rectHighLife);
222 SDL_RenderCopy(renderer, textStart, NULL, &rectStart);
223 SDL_RenderCopy(renderer, textGoal, NULL, &rectGoal);
224 SDL_RenderCopy(renderer, textSubGoal, NULL, &rectSubGoal);
226 SDL_RenderPresent(renderer);
229 void ModeSelect::close() {
230 destroyFonts();
231 if (!mouseClickedR) {
232 fadeOutMusic(500);
233 SDL_Delay(500);
235 else {
236 animations.at(1)->destroyAnimation();
237 animations.at(0)->destroyAnimation();
239 skip = true;
242 std::array<Animation*, 2> ModeSelect::getAnimations() {
243 return animations;
246 bool ModeSelect::getSkip() {
247 return skip;